package com.li.controller;/**
 * @author sun
 * @date 2022/3/21 - 0:18
 */

import com.li.pojo.Feedback;
import com.li.service.FeedbackService;
import com.li.utils.R;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: TODO
 * @author
 * @date 2022/3/21 0:18
 * @version 1.0
 */
@RestController
@Api(tags="feedBack模块")
@CrossOrigin
@RequestMapping("/feedBack")
public class FeedbackController {
    @Autowired
    private FeedbackService feedBackService;

    @PostMapping("/insertFeedback")
    @ApiOperation(value="增加Feedback")
    public R insertFeedback(Feedback feedBack){
        try {

            feedBackService.insertSelective(feedBack);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }

    }


    @GetMapping("/deleteFeedback")
    @ApiOperation(value="删除Feedback")
    public R deleteFeedback(Integer id){
        try {
            feedBackService.deleteByPrimaryKey(id);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @PutMapping("/updateFeedback")
    @ApiOperation(value="更新Feedback")
    /*@Transactional(rollbackFor = Exception.class)*/
    public R updateFeedback(@RequestBody Feedback feedBack){
        try {
            feedBackService.updateByPrimaryKeySelective(feedBack);
           /* feedBackRedirectcontentService.updateByPrimaryKeySelective(feedBackRedirectcontent);*/
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @GetMapping("/findFeedbackList")
    @ApiOperation(value="查询FeedbackList")
    public R findFeedback(Feedback feedBack,Integer pageNum,Integer pageSize){
        try {
            List<Feedback> list= feedBackService.findFeedback(feedBack,pageNum,pageSize);
            return R.ok().data("feedBackList",list);
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @GetMapping("/findFeedbackById")
    @ApiOperation(value="通过id查询Feedback")
    public R findFeedbackById(Integer id){
        try {
            Feedback feedBack= feedBackService.selectByPrimaryKey(id);
            return R.ok().data("feedBack",feedBack);
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

}
